import GET from '@/interfaces/ajax'
import _ from 'lodash'

let Get = GET.Get
const Category = {
    namespaced: true,
    state() {
        return {
            categoryList: [],
            categoryChildrens: []
        }
    },
    actions: {
        async getLeftList({ commit }) {
            let res = await Get(config.interface.getCategoryList)
            commit('categoryMehts', res.data)
        },
        async getRightList({ commit }, id) {         
            let res = await Get(config.interface.getCategoryRelChild + '?cate_id=' + id)
            console.log(res, 'resresresresresresres')
            // _.take(res.data)默认取res.data这个数据里的第一项
            commit('categoryChildrensMeths', _.take(res.data))
        }
    },
    mutations: {
        categoryMehts(state, list) {
            state.categoryList = list
        },
        categoryChildrensMeths(state, rightList) {
            state.categoryChildrens = rightList
        }
    }
}

export default Category
